<template>
  <div  align='center'>
      <div style="width:500px;" align='center'>
        <van-cell-group inset>
            <van-field v-model="from.username" label="用户名" placeholder="请输入用户名" />
            <van-field v-model="from.password" label="密&emsp;码" placeholder="请输入密  码" />
            <van-button type="primary" @click="login">登录</van-button>
        </van-cell-group>

    </div>
    <ul>
        <li v-for="i in getlist" :key='i'>
            <button @click="auild(i.id)">{{i.name}}</button>
            <!-- <user/> -->
        </li>
    </ul>
    <!-- {{getlist}} -->
  </div>
</template>

<script>
import myaxios from 'axios'
export default {
    data(){
        return{
            from:{},
            id:0,
            getlist:[]
        }
    },
    methods:{
        login(){
            myaxios({url:'http://127.0.0.1:5000/users',method:'post',data:this.from}).then(res=>{
                console.log(res.data.list)
                this.getlist = res.data.list
                localStorage.setItem('id',res.data.id)
                localStorage.setItem('username',res.data.username)
                localStorage.setItem('list',JSON.stringify(res.data.list))
                this.$toast.fail("欢迎你");
                this.$router.push({path:'/getlist'})
            })    
        },
        auild(id){
            this.id=id
            console.log(id)
        }
    }
}
</script>

<style>

</style>